﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.Web.Routing;
using System.Globalization;
using MvcEngine.Core;
using MvcEngine.Core.Localization;

namespace MvcEngine.Mvc.Extensions
{
    public static class LinkExtensions
    {
//        #region SiteLinkActions
//#warning remove this functions
//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, null, new RouteValueDictionary(), new RouteValueDictionary());
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, null, new RouteValueDictionary(routeValues), new RouteValueDictionary());
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, controllerName, new RouteValueDictionary(), new RouteValueDictionary());
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, null, routeValues, new RouteValueDictionary());
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, null, new RouteValueDictionary(routeValues), new RouteValueDictionary(htmlAttributes));
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, null, routeValues, htmlAttributes);
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
//        {
//            return htmlHelper.SiteActionLink(linkText, actionName, controllerName, new RouteValueDictionary(routeValues), new RouteValueDictionary(htmlAttributes));
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
//        {
//            if (string.IsNullOrEmpty(linkText))
//            {
//                throw new ArgumentException(string.Format(ResourceReader.Current.GetString("NullOrEmptyValue"), "linkText"));
//            }

//            if (!string.IsNullOrEmpty(SiteContext.Current.Site.Alias))
//            {
//                routeValues.Add("alias", SiteContext.Current.Site.Alias);
//            }

//            string link = htmlHelper.RouteCollection.GetVirtualPath(htmlHelper.ViewContext.RequestContext, routeValues).VirtualPath;
//            return HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null, actionName, controllerName, routeValues, htmlAttributes);
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes, string innerTag)
//        {
//            return SiteActionLink(htmlHelper, linkText, actionName, routeValues, htmlAttributes, innerTag, null);
//        }

//        public static string SiteActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes, string innerTag, string alias)
//        {
//            string outLink = null;
//            string aliasPath = string.Empty;

//            if (string.IsNullOrEmpty(linkText))
//            {
//                throw new ArgumentException("Value cannot be null or empty.", "linkText");
//            }

//            if (string.IsNullOrEmpty(innerTag))
//            {
//                throw new ArgumentException("Value cannot be null or empty.", "innerTag");
//            }

//            RouteValueDictionary routes = new RouteValueDictionary(routeValues);
//            if (!string.IsNullOrEmpty(SiteContext.Current.Site.Alias))
//            {
//                routes.Add("alias", SiteContext.Current.Site.Alias);
//                aliasPath = "/" + SiteContext.Current.Site.Alias;
//            }
//            aliasPath += "/" + alias;

//            RequestContext context = new RequestContext(htmlHelper.ViewContext.HttpContext, new RouteData());
//            string link = htmlHelper.RouteCollection.GetVirtualPath(context, routes).VirtualPath;

//            if (!string.IsNullOrEmpty(alias))
//            {
//                Uri url = htmlHelper.ViewContext.HttpContext.Request.Url;
//                string protocol = !string.IsNullOrEmpty(url.Scheme) ? url.Scheme : Uri.UriSchemeHttp;
//                string str2 = string.Empty;
//                string scheme = url.Scheme;
//                if (string.Equals(protocol, scheme, StringComparison.OrdinalIgnoreCase))
//                {
//                    str2 = url.IsDefaultPort ? string.Empty : (":" + Convert.ToString(url.Port, CultureInfo.InvariantCulture));
//                }

//                outLink = protocol + Uri.SchemeDelimiter + url.Host + str2 + aliasPath;
//            }

//            TagBuilder tagBuilder = new TagBuilder(innerTag);
//            tagBuilder.InnerHtml = linkText;
//            TagBuilder builder = new TagBuilder("a");
//            builder.InnerHtml = tagBuilder.ToString(TagRenderMode.Normal);
//            builder.MergeAttributes<string, object>(new RouteValueDictionary(htmlAttributes));
//            builder.MergeAttribute("href", outLink ?? link);
//            return builder.ToString(TagRenderMode.Normal);
//        }
//        #endregion

        //#region SiteRouteLink
        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, new RouteValueDictionary(routeValues));
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, routeValues, new RouteValueDictionary());
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues, object htmlAttributes)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, new RouteValueDictionary(routeValues), new RouteValueDictionary(htmlAttributes));
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, routeName, new RouteValueDictionary(routeValues));
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, routeName, routeValues, new RouteValueDictionary());
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, null, routeValues, htmlAttributes);
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes)
        //{
        //    return htmlHelper.SiteRouteLink(linkText, routeName, new RouteValueDictionary(routeValues), new RouteValueDictionary(htmlAttributes));
        //}

        //public static string SiteRouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
        //{
        //    if (string.IsNullOrEmpty(linkText))
        //    {
        //        throw new ArgumentException(string.Format(ResourceReader.GetString("NullOrEmptyValue"), "linkText"));
        //    }
        //    if (!string.IsNullOrEmpty(SiteContext.Current.CurrentSite.Alias))
        //    {
        //        routeValues.Add("alias", SiteContext.Current.CurrentSite.Alias);
        //    }
        //    return HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, routeName, routeValues, htmlAttributes);
        //}


        //#endregion


    }
}
